package com.zhangxi.controller.user;

import com.zhangxi.constant.StatusConstant;
import com.zhangxi.entity.Dish;
import com.zhangxi.entity.SetMeal;
import com.zhangxi.result.Result;
import com.zhangxi.service.DishService;
import com.zhangxi.service.SetMealService;
import com.zhangxi.vo.DishItemVO;
import com.zhangxi.vo.DishVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zhangxi
 * @create 2024-04-24 19:13
 */
@RestController("SetMealController")
@RequestMapping("/user/setmeal")
@Slf4j
@Api(tags = "C端套餐接口")
public class SetMealController {
    @Autowired
    private DishService dishService;

    @Autowired
    private SetMealService setMealService;


    /**
     * 根据分类id查询套餐
     * @param categoryId
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("根据分类id查询套餐")
    @Cacheable(cacheNames = "SetMealCache",key = "#categoryId") //key: setMealCache::100
    public Result list(Long categoryId){
        SetMeal setMeal = new SetMeal();
        setMeal.setCategoryId(categoryId);
        setMeal.setStatus(StatusConstant.ENABLE);

        List<SetMeal> list = setMealService.list(setMeal);
        return Result.success(list);
    }

    /**
     * 根据套餐id查询包含的菜品
     * @param id
     * @return
     */
    @GetMapping("/dish/{id}")
    @ApiOperation("根据套餐id查询包含的菜品列表")
    public Result dish(@PathVariable Long id){

        List<DishItemVO> list = setMealService.getDishItemById(id);

        return Result.success(list);
    }
}
